﻿using IOP.SgrA;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace VkSample113;

public class WaveAnimation : Animation
{
    private Uniform Uniform = new Uniform() { WidthSpan = 12.0f };
    private float uStartAngle = 0;
    private float uWidthSpan = 12.0f;
    private ITexture? Texture;
    public override void CloneToNewRender(IRenderObject newObj)
    {
        var f = new WaveAnimation();
        f.Name = Name;
        newObj.AddComponent(f);
        f.OnAttach(newObj);
    }

    public override void OnAttach(IRenderObject @object)
    {
        RenderObject = @object;
        Texture = RenderObject.GetComponents<ITexture>().Where(x => x.SetIndex == 0 && x.Binding == 0).FirstOrDefault();
    }

    public override void Play(TimeSpan timeSpan)
    {
        if (uStartAngle < 3) uStartAngle -= 0.1f * (float)timeSpan.TotalSeconds * 25;
        if (uStartAngle > 0) uStartAngle += 0.1f * (float)timeSpan.TotalSeconds * 25;
        Uniform.WidthSpan = uWidthSpan;
        Uniform.StartAngle = uStartAngle;
        Texture?.UpdateTextureMemoryData(Uniform);
    }
}

public struct Uniform
{
    public float WidthSpan;
    public float StartAngle;
}
